<template>

  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-form label-width="40px" inline style="text-align: center">
      <el-form-item label="标题">
         <el-input placeholder="请输入内容" prefix-icon="el-icon-search" v-model="param.title"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="loadArticles">搜索</el-button>
      </el-form-item>
       <el-form-item style="text-align-right">
        <el-button type="primary" size="small" @click="toAddHandler">新增文章</el-button>
      </el-form-item>
      </el-form>       
    </div>  
     <!-- /按钮 -->
    <!-- {{baseuserroles}} -->
    <!-- 表格 -->
     <el-table size="small" :data="articles">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="标题" prop="title" align="center"></el-table-column>
      <el-table-column label="简介" prop="brief" align="center"></el-table-column>
      <el-table-column label="内容"  prop="content" align="center"></el-table-column>
      <el-table-column label="发表时间" prop="publishTime"   align="center"></el-table-column>
      <el-table-column label="阅读次数"  prop="readTimes"  align="center" ></el-table-column>
      <el-table-column label="状态"  prop="status" align="center"></el-table-column>
      <el-table-column label="点赞数" prop="thumpUp" align="center"></el-table-column>
      <el-table-column label="参考文献" prop="cover" align="center"></el-table-column>
      <el-table-column label="作者ID" prop="authorId" align="center"></el-table-column>
      <el-table-column label="类别ID" prop="categoryId" align="center"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
      <template slot-scope="scope">
        <el-button type="text"  size="mini" @click="editHandler(scope.row)">修改</el-button> 
        <el-button type="text"  size="mini" @click="deleteHandler(scope.row)">删除</el-button>
      </template>

      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>

<script>
import { del, get,} from "@/utils/request";
export default {
  //页面数据
  data() {
    return {
      articles: [],
      param: {},
    };
  },
  //页面渲染的时候会调用的函数
 
  
  methods: {
    //修改
    editHandler(row){
      //跳转到修改页面（新增）
      //携带当前行所带数据
      this.$router.push({
        path:"/article/create",  //跳转的路由
        query:row  //携带参数
      })
    },
    addThumpUp(row){
       this.$router.push({
        path:"/article/create",  //跳转的路由
        query:row  //携带参数
       
       })
    },
    //删除
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://localhost:8888/article/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadArticles();
        });
      });
    },
    //跳转
    toAddHandler() {
      this.$router.push("/article/create");
    },
    //
    loadArticles() {
      let url = "http://localhost:8888/article/query";
      get(url, this.param).then((resp) => {
        this.articles = resp.data;
      });
    },
  },
    
    created() {
      this.loadArticles();
    
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>